//
//  DCCarDetailMsgViewController.m
//  JiuyaoMotorcade
//
//  Created by 大橙子 on 2018/12/1.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCCarDetailMsgViewController.h"
#import "DCCarDetailMsgView.h"
#import "DCIDCardImagePicker.h"
@interface DCCarDetailMsgViewController ()<TZImagePickerControllerDelegate>
@property (nonatomic,assign) BOOL isEdit;
@property (nonatomic,strong) DCCarDetailMsgView *plate;
@property (nonatomic,strong) DCCarDetailMsgView *VIN;
@property (nonatomic,strong) DCCarDetailMsgView *fadongji;
@property (nonatomic,strong) DCCarDetailMsgView *carNum;
@property (nonatomic,strong) UITextField *driverName;
@end

@implementation DCCarDetailMsgViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"车辆详情";
    self.view.backgroundColor = [UIColor whiteColor];
    [self setUpUI];
}
-(void)setUpUI {
    
    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, ScreenHeight - navHeight-statusHeight - 40)];
    scrollView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:scrollView];
    
    DCCarDetailMsgView *plate = [[DCCarDetailMsgView alloc]initWithFrame:CGRectMake(10, 10, self.view.width - 20, 40)];
    plate.imageView.image = IMAGENAME(@"车牌 (2)");
    plate.textField.text = @"plate";
    plate.textField.placeholder = @"请输入车牌号";
    self.plate = plate;
    [scrollView addSubview:plate];
    
    DCCarDetailMsgView *VIN = [[DCCarDetailMsgView alloc]initWithFrame:CGRectMake(10, plate.bottom+5, self.view.width - 20, 40)];
    VIN.imageView.image = IMAGENAME(@"vin");
    VIN.textField.text = @"VIN";
    VIN.textField.placeholder = @"请输入车架号";
    self.VIN = VIN;
    [scrollView addSubview:VIN];
    
    DCCarDetailMsgView *fadongji = [[DCCarDetailMsgView alloc]initWithFrame:CGRectMake(10, VIN.bottom+5, self.view.width - 20, 40)];
    fadongji.imageView.image = IMAGENAME(@"发动机");
    fadongji.textField.text = @"fadongji";
    fadongji.textField.placeholder = @"请输入发动机号";
    self.fadongji = fadongji;
    [scrollView addSubview:fadongji];
    
    DCCarDetailMsgView *carNum = [[DCCarDetailMsgView alloc]initWithFrame:CGRectMake(10, fadongji.bottom+5, self.view.width - 20, 40)];
    carNum.imageView.image = IMAGENAME(@"车牌-1");
    carNum.textField.text = @"carNum";
    carNum.textField.placeholder = @"请输入载车位数";
    self.carNum = carNum;
    [scrollView addSubview:carNum];
    
    UIImageView *driverImage = [[UIImageView alloc]init];
    driverImage.image = IMAGENAME(@"司机_dark");
    driverImage.size = CGSizeMake(50, 40);
    driverImage.x = carNum.x;
    driverImage.y = carNum.bottom;
    [scrollView addSubview:driverImage];
    
    self.driverName = [[UITextField alloc]initWithFrame:CGRectMake(driverImage.right, carNum.bottom, scrollView.width - 20-driverImage.width, 40)];
    self.driverName.text = @"张三 15012345678";
    self.driverName.font = FONT(16);
    self.driverName.textAlignment = NSTextAlignmentRight;
    [scrollView addSubview:self.driverName];

    
    CGFloat kMargin = 13;
    CGFloat btnW = (self.view.width - kMargin*3)/2;
    CGFloat btnH = 130*HEIGHTSCALE6;
    __weak typeof(self) weakself = self;
    
    DCIDCardImagePicker *firstImageView = [[DCIDCardImagePicker alloc]initWithFrame:CGRectMake(kMargin, self.driverName.bottom+20+kMargin, btnW, btnH)];
    firstImageView.titleLabel.attributedText = [YLAttributedStr changeSubStringWithTotalString:@"行驶证" subStringColor:[UIColor blackColor] subString:@"行驶证" andFont:FONT(16)];
    firstImageView.block = ^(UIImageView * _Nonnull imageView) {
        
        TZImagePickerController *imageVC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
        [imageVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            imageView.image = photos[0];
        }];
        [weakself presentViewController:imageVC animated:YES completion:nil];
    };
    [scrollView addSubview:firstImageView];
    
    DCIDCardImagePicker *secondImageView = [[DCIDCardImagePicker alloc]initWithFrame:CGRectMake(kMargin+firstImageView.right, firstImageView.y, btnW, btnH)];
    secondImageView.titleLabel.attributedText = [YLAttributedStr changeSubStringWithTotalString:@"行驶证(副证)" subStringColor:[UIColor blackColor] subString:@"行驶证" andFont:FONT(16)];
    secondImageView.block = ^(UIImageView * _Nonnull imageView) {
        
        TZImagePickerController *imageVC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
        [imageVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            imageView.image = photos[0];
        }];
        [weakself presentViewController:imageVC animated:YES completion:nil];
    };
    [scrollView addSubview:secondImageView];
    
    DCIDCardImagePicker *thirdImageView = [[DCIDCardImagePicker alloc]initWithFrame:CGRectMake(firstImageView.x, firstImageView.bottom+kMargin, btnW, btnH)];
    thirdImageView.titleLabel.attributedText = [YLAttributedStr changeSubStringWithTotalString:@"运营证" subStringColor:[UIColor blackColor] subString:@"运营证" andFont:FONT(16)];
    thirdImageView.block = ^(UIImageView * _Nonnull imageView) {
        TZImagePickerController *imageVC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
        [imageVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            imageView.image = photos[0];
        }];
        [weakself presentViewController:imageVC animated:YES completion:nil];
        
    };
    [scrollView addSubview:thirdImageView];
    
    DCIDCardImagePicker *forthImageView = [[DCIDCardImagePicker alloc]initWithFrame:CGRectMake(secondImageView.x, thirdImageView.y, btnW, btnH)];
    forthImageView.titleLabel.attributedText = [YLAttributedStr changeSubStringWithTotalString:@"运营证(副证)" subStringColor:[UIColor blackColor] subString:@"运营证" andFont:FONT(16)];
    forthImageView.block = ^(UIImageView * _Nonnull imageView) {
        TZImagePickerController *imageVC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
        [imageVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            imageView.image = photos[0];
        }];
        [weakself presentViewController:imageVC animated:YES completion:nil];
        
    };
    [scrollView addSubview:forthImageView];
    
    
    UIButton * surtBtn = [[UIButton alloc]init];
    [surtBtn setTitle:@"提交" forState:UIControlStateNormal];
    surtBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [surtBtn addTarget:self action:@selector(surtBtnOnClicked) forControlEvents:UIControlEventTouchUpInside];
    surtBtn.layer.cornerRadius = 20;
    surtBtn.layer.masksToBounds = YES;
//    surtBtn.backgroundColor = BlueColor;
    surtBtn.layer.borderWidth = 1;
    surtBtn.layer.borderColor = BlueColor.CGColor;
    [surtBtn setTitleColor:BlueColor forState:UIControlStateNormal];
    [self.view addSubview:surtBtn];
    [surtBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_offset(35);
        make.left.equalTo(weakself.view.mas_left).offset(50);
        make.right.equalTo(weakself.view.mas_right).offset(-50);
        make.bottom.equalTo(weakself.view.mas_bottom).offset(-7);
    }];
    
    scrollView.contentSize = CGSizeMake(self.view.width, CGRectGetMaxY(forthImageView.frame)+40);
}

-(void)surtBtnOnClicked {
    DCLogFunc;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
